<template>
  <div class="fresh">
    <div class="product-banner">
      <div class="swiper-container2">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="item in imgAtlas">
            <img :src="comimgsrc+item" alt="">
          </div>
        </div>
        <div class="swiper-pagination"></div>
      </div>
    </div>
    <div class="downbox">
      <img :src="bg1" class="bgimg">
      <div class="cont">
        <p class="p-name">{{detail.name}}</p>
        <div class="price">
          <p class="p-price">价格：<span>￥{{detail.price}}/{{detail.unit}}</span></p>
          <del class="del">原价：{{detail.max_price}}/{{detail.unit}}</del>
        </div>
        <p class="p-sm">{{detail.instructions}}</p>
      </div>
    </div>
    <div class="numbox">
      <p class="left">选择数量：</p>
      <div class="box">
        <div class="btn" @click="redusnum"><i class="icon iconfont icon-jian"></i></div>
        <input v-model="number" disabled="disabled" />
        <div class="btn" @click="addnum"><i class="icon iconfont icon-jiahao"></i></div>
      </div>
    </div>
    <div class="pl">
      <div class="pl-head">商品评价</div>
      <div class="box">
        <p v-show="!comment">暂无评论</p>
        <div class="list" v-for="item in comment">
          <div class="list-head">
            
            <img v-if="item.headimg" :src="comimgsrc+item.headimg" alt="">
            <img v-else :src="cp1" alt="">
            <div class="name">{{item.username}}</div>
            <p class="time">{{item.create_time}}</p>
          </div>
          <p class="txt">{{item.content}}</p>
          <div class="rate">
            <p style="float: left;">评分：</p><el-rate disabled text-color="#ef5a68" :value="item.star" show-text></el-rate>
          </div>
          <div class="alts">
            <div class="img" v-for="imgs in item.img" v-show="imgs">
              <div class="cont">
                <img :src="comimgsrc+imgs">
              </div>
            </div>
          </div> 
        </div>
      </div>
      <div class="more" v-show="comment" @click="gocomment()">查看全部评论</div>
    </div>
    <div class="xq pl">
      <div class="pl-head">商品详情</div>
      <div class="editbox" v-html="detail.description">
        
      </div>
    </div>
    <div class="downsc"></div>
    <div class="fixedown">
      <div class="btn ljgm" v-if="detail.start_time > 0 || ttime < 0" @click="yydj()">立即购买</div>
      <div class="btn ljgm ljgm-act" v-else @click="gobuy(detail.id,number,detail.price)">立即购买</div>
      <div class="btn" v-if="detail.start_time>0 ">
        <p style="margin-top:.14rem;line-height: 1;font-size: .2rem;">距开始：</p>
        <djsstart @ieventstart="ieventstart($event)" v-bind:endtime="{sj:detail.start_time,id:detail.id,stock:detail.stock}"></djsstart>
      </div>
      <div class="btn" v-else>
        <p style="margin-top:.14rem;line-height: 1;font-size: .2rem;">距结束：</p>
        <djsend @ievent="ievent($event)" v-bind:endtime="{sj:detail.deadline,id:detail.id,stock:detail.stock}"></djsend>
      </div>
    </div>
  </div>
</template>
<script>
import qs from 'qs';
import ban1 from '@/assets/image/banner1.jpg';
import bg1 from '@/assets/image/bg1.png';
import cp1 from '@/assets/image/cp1.jpg';
// import store from '@/vuex/store'
import store from '@/vuex/store'
import djsstart from '@/components/common/djs-start';
import djsend from '@/components/common/djs-end';
export default {
	name: 'index',
  	data () {
  		return{
        ban1,bg1,cp1,
        detail:[],
        imgAtlas:[],
        comimgsrc:'http://api.mountainfreshes.com',
        number:1,
        tximg:cp1,
        comment:[],
        ttime:0,
        sssid:''
  		}
  	},
  	methods:{
      
      gobuy:function(id,num,price){
            if(this.$store.state.dlzt==1){
              this.$http.post("/index.php/user/order/purchase_immediately",qs.stringify({
              // mobile:this.tel,
              // password:this.pwd
                  user_id: this.$store.state.userid,
                  good_id: id,
                  quantity: num,
                  price: price

              }))
              .then(res => {
                console.log(res.data.row)
                this.$router.push({ path: '/buystep',query:{cplist: res.data.row} })
              })
              .catch(error => {
                alert("网络错误")
              });
            }else{
              this.$messagebox.confirm('还没有登录，现在就去登录','未登录',{confirmButtonText:'去登录',cancelButtonText:'先逛逛'})
              .then(() => {
                this.$router.push({ name: 'login' })
              }).catch(() => {
                        
              });
            }
          },
      gocomment:function(){
        let cpid = this.$route.query.cpid
        this.$router.push({ name: 'detailComment', query:{cpid: cpid} })
      },
      getcpId:function(){
        let cpid = this.$route.query.cpid
        console.log(cpid)
        this.$http.get("/index.php/index/goods/getGoodsInfo?ids="+cpid)
        .then(res => {
          this.detail = res.data
          // this.xsglist = res.data;
          console.log(this.detail)
          this.imgAtlas = res.data.atlas
        })
        .catch(error => {
              
        });
      },
      redusnum:function(){
        if(this.number == 1){
          this.number = 1;
        }else{
          this.number--
        }
      },
      addnum:function(){
        this.number++
      },
      getsppl:function(){
        this.$http.post("/index.php/index/content/onelist",qs.stringify({
              // mobile:this.tel,
              // password:this.pwd
                  good_id: this.$route.query.cpid

              }))
              .then(res => {
                this.comment = res.data.row
                console.log(this.comment)
              })
              .catch(error => {
                alert("网络错误")
              });
      },
      ieventstart(ev){
            this.detail.start_time = ev.did;
            // console.log(ev.did,ev.index)
          },
          ievent(ev){
            // this.sssid = ev.did;
            // this.xsglist[ev.did].time = 0;
           this.sssid = ev.did;
           // console.log(this.sssid)
          },
  	},
  	components:{
        djsend,djsstart
  	},
  	mounted(){
      var swiper2 = new Swiper('.swiper-container2', {
        pagination: '.swiper-pagination',
        paginationClickable: true,
        autoplay: 4000,
        paginationType: 'fraction',
        observer:true,//修改swiper自己或子元素时，自动初始化swiper
        observeParents:true,//修改swiper的父元素时，自动初始化swiper
      });
    },
    created(){
      this.getcpId();
      this.getsppl();
    },
    watch:{
          '$route' (to, from) {
                // this.getinfo()
               //   const toDepth = to.path.split('/').length
                // const fromDepth = from.path.split('/').length
                // this.transitionName = toDepth < fromDepth ? 'slide-right' : 'slide-left'
                // console.log(to.name)
                if(to.name == 'limitDetail'){
                  this.getcpId();
                  this.getsppl();
                  this.number=1;
                }
              }
        }
}
</script>
<style scoped lang="less">
.downsc{
  width: 100%;
  height: .96rem;
}
.fixedown{
  width: 100%;
  height: .86rem;
  position: fixed;
  z-index: 9;
  bottom: 0;
  left: 0;
  background: #737373;
  color: #fff;
  line-height: .86rem;
  font-size: .24rem;
  .ljgm{
    background: #929292;
  }
  .ljgm-act{
    background: #54b84c;
  }
  .btn{
    width: 50%;
    float: left;
    height: 100%;
  }
}
.pl{
  width: 100%;
  height: auto;
  zoom: 1;
  overflow: hidden;
  .pl-head{
    padding: 0 .2rem;
    height: .6rem;
    line-height: .6rem;
    font-size: .26rem;
    text-align: left;
    border-bottom: 1px solid #d6d6d6;
  }
  .box{
    padding: .2rem;
    height: auto;
    zoom: 1;
    overflow: hidden;
    .list{
      width: 100%;
      height: auto;
      zoom: 1;
      overflow: hidden;
      text-align: left;
      .list-head{
        width: 100%;
        height: .72rem;
        img{
          display: block;
          width: .72rem;
          height: .72rem;
          float: left;
          border-radius: 100%;
          overflow: hidden;
        }
        .name{
          width: 3.2rem;
          height: 100%;
          font-size: .24rem;
          color: #333;
          font-size: .24rem;
          line-height: .72rem;
          text-align: left;
          float: left; 
          margin-left: .14rem;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .time{
          float: right;
          line-height: .72rem;
          color: #666;
          font-size: .22rem;
        }
      }
      .txt{
        font-size: .22rem;
        color: #333;
        padding-top: .12rem;
      }
      .rate{
        font-size: .22rem;
        margin-top: .1rem;
      }
      .alts{
        width: 100%;
        height: auto;
        zoom: 1;
        overflow: hidden;
        margin-top: .1rem;
        .img{
          width: 1.36rem;
          height: 1.2rem;
          float: left;
          margin-left: 0.1866666666666666rem;
          background: #d6d6d6;
          margin-bottom: .1rem;
          &:nth-child(4n+1){
            margin-left: 0;
          }
          .cont{
            width: 1.36rem;
            height: 1.2rem;
            text-align: center;
            display: table-cell;
            vertical-align: middle;
            overflow: hidden;
            img{
              max-width: 100%;
              max-height: 100%;
              vertical-align: middle;
              display: hidden;
              transform: scale(1);
              transition: all ease 0.2s;
            }
          }
        }
      }
    }
  }
  .editbox{
    padding: .2rem;
    height: auto;
    zoom: 1;
    overflow: hidden;
    text-align: left;
    p{
      img{
        display: block;
        max-width: 100%;
      }
    }
  }
  .more{
    width: 2.2rem;
    height: .52rem;
    border: 2px solid #b5b5b5;
    border-radius: 4px;
    margin: 0rem auto .2rem;
    color: #666;
    line-height: .52rem;
    font-size: .24rem;
  }
}
.numbox{
  height: .88rem;
  background: #fff;
  padding: 0 .2rem;
  border-bottom: .1rem solid #f5f5f5;
  .left{
    float: left;
    line-height: .88rem;
    font-size: .24rem;
  }
  .box{
    width: 2.5rem;
    height: .52rem;
    float: left;
    border: .02rem solid #cccccc;
    margin-top: .16rem;
    margin-left: 1rem;
    .btn{
      float: left;
      width: .62rem;
      height: .52rem;
      line-height: .52rem;
      font-size: .3rem;
      color: #000;
    }
    input{
      display: block;
      height: .52rem;
      float: left;
      width: 1.26rem;
      box-sizing: border-box;
      text-align: center;
      font-size: .28rem;
      border: none;
      outline: none;
      border-right: .02rem solid #cccccc;
      border-left: .02rem solid #cccccc;
    }
  }
}
.product-banner{
  width: 100%;
  height: 4rem;
  overflow: hidden;
  position: relative;
  .swiper-container2{
    width: 100%;
    height: 100%;
    overflow: hidden;
    img{
      display: block;
      width: 100%;
      height: 100%;
    }
    .swiper-pagination-fraction{
      width: 60px;
      height: 24px;
      font-size: 14px;
      background: rgba(0,0,0,.6);
      color: #fff;
      border-radius: 12px;
      left: 5rem;
      line-height: 24px;
    }
  }
}
.downbox{
  width: 100%;
  height: auto;
  zoom: 1;
  overflow: hidden;
  position: relative;
  .bgimg{
    width: 100%;
    height: 100%;
    position: absolute;
    z-index: -1;
    display: block;
    left: 0;
    top: 0;
  } 
  .cont{
    padding: .2rem;
    text-align: left;
    height: auto;
    zoom: 1;
    overflow: hidden;
    .p-name{
      font-size: .28rem;
      color: #131313;
    }
    .price{
      width: 100%;
      float: left;
      margin-top: .1rem;
      .p-price{
        font-size: .24rem;
        color: #333;
        float: left;
        line-height: .46rem;
        span{
          font-size: .3rem;
          color: #50b748;
        }
      }
      .del{
        font-size: .22rem;
        color: #333;
        line-height: .46rem;
        float: left;
        margin-left: .2rem;
      }
    }
    .p-sm{
      font-size: .22rem;
      color: #131313;
      margin-top: .06rem;
      float: left;
    }
  }
}
</style>